package com.dingding.common.core.base.dto;

import org.apache.http.HttpStatus;

import com.dingding.common.core.base.code.BaseCodeMessage;
import com.dingding.common.core.util.paravalidate.ValiResult;
import com.dingding.common.core.util.paravalidate.ValidateUtil;

public class AbstractValiResponse {

	/**
	 * 验证客户端请求参数是否合法
	 * 
	 * @Title: validateParam
	 * @author CHEHAUNBO
	 * @since V2.2.0
	 * 
	 */
	protected boolean validateParam(Object reqCalculateDistance) {
		return ValidateUtil.validateBean(reqCalculateDistance, reqCalculateDistance.getClass());
	}

	/**
	 * 
	 * 响应数据给客户端端
	 * @param statusCode 状态码
	 * @param errorMsg 错误信息
	 * @param promptmsg 友好提示信息
	 * @return ResponseEntity<T> http响应数据封装Bean
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	protected <T> ResponseEntity<T> error(int statusCode, String errorMsg, String promptmsg) {

		ResponseEntity<T> responseEntity = new ResponseEntity<T>();
		responseEntity.setCode(HttpStatus.SC_FORBIDDEN);
		responseEntity.setErrorMessage(errorMsg);
		responseEntity.setPromptMessage(promptmsg);

		return responseEntity;

	}

	/**
	 * 
	 * 验参失败响应给客户端
	 * 
	 * @Title: validateParam 
	 * @param valiResult 验参结果封装bean
	 * @return ResponseEntity<T> http响应数据封装Bean
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	protected <T> ResponseEntity<T> error(ValiResult valiResult) {

		ResponseEntity<T> responseEntity = new ResponseEntity<T>();
		responseEntity.setCode(HttpStatus.SC_FORBIDDEN);
		responseEntity.setNullPropList(valiResult.getNullFieldList()); // 空字段名称
		responseEntity.setErrorMessage(BaseCodeMessage.DATA_NULL_PARAM_MESSAGE);
		responseEntity.setPromptMessage(BaseCodeMessage.HTTP_REQUEST_ERROR);

		return responseEntity;

	}

	/**
	 * 
	 * 响应数据给客户端端
	 * @Title: validateParam
	 * @param resBody 响应内容
	 * @param statusCode 状态码
	 * @return ResponseEntity<T> http响应数据封装Bean
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	protected <T> ResponseEntity<T> success(int statusCode) {

		ResponseEntity<T> responseEntity = new ResponseEntity<T>();

		responseEntity.setCode(statusCode);

		return responseEntity;

	}

	/**
	 * 
	 * 响应数据给客户端端
	 * @Title: validateParam
	 * @param resBody 响应内容
	 * @param statusCode 状态码
	 * @return ResponseEntity<T> http响应数据封装Bean
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	protected <T> ResponseEntity<T> success(T resBody, int statusCode) {

		ResponseEntity<T> responseEntity = new ResponseEntity<T>();

		responseEntity.setCode(statusCode);
		responseEntity.setResponseBody(resBody);

		return responseEntity;

	}

}
